package com.xxt.wuhao.fanacfun;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

    @BindView(R.id.mainLayout)
    FrameLayout mMainLayout;
    @BindView(R.id.mainNavigation)
    NavigationView mMainNavigation;
    private FragmentTransaction mFragmentTransaction;
    private HomeFragment mHomeFragment;
    private CacheFragment mCacheFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mMainNavigation.setNavigationItemSelectedListener(this);
        FragmentManager fragmentManager = getFragmentManager();
        mFragmentTransaction = fragmentManager.beginTransaction();
        mHomeFragment = new HomeFragment();
        mCacheFragment = new CacheFragment();

        mFragmentTransaction.add(R.id.mainLayout,mHomeFragment,"home");
        mFragmentTransaction.add(R.id.mainLayout,mCacheFragment,"cache");
        mFragmentTransaction.hide(mHomeFragment);
        mFragmentTransaction.hide(mCacheFragment);
        mFragmentTransaction.commit();

    }


    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.hide(mHomeFragment);
        fragmentTransaction.hide(mCacheFragment);

        int itemId = item.getItemId();
        switch (itemId) {
            case R.id.menu_home:
                fragmentTransaction.show(mHomeFragment);
                fragmentTransaction.commit();
                break;
            case R.id.menu_cache:
                fragmentTransaction.show(mCacheFragment);
                fragmentTransaction.commit();
                break;
            case R.id.menu_my_collect:
                break;
            case R.id.menu_my_focus:
                break;
            case R.id.menu_wait_look:
                break;
            case R.id.menu_big_vip:
                break;
            case R.id.menu_free_flow:
                break;
            case R.id.menu_BML_order:
                break;

        }
        return true;
    }
}
